﻿/*
 * Copyright (c) 2013, Juergen Bocklage-Ryannel, Johan Thelin
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the editors nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

// animate.qml

//导入 Qt快速 2.5
import QtQuick 2.5

Item {
    //设置ID为root，root为根的意思
    id: root
    //设置宽度为背景宽度
    width: background.width
    //设置高度为背景高度
    height: background.height

    //设置跟属性rotationStep为45，旋转幅度
    property int rotationStep: 45

    Image {
        //设置ID为background，background为背景的意思
        id: background
        //设置背景图片，资源路径相对路径为 "images/background.png"
        source: "images/background.png"
    }

    Image {
        //设置ID为pole，pole为杆的意思
        id: pole
        //x位置为(根模块的宽度-本模块宽度)/2 +2，就是居中的意思。
        x: (root.width - width)/2+2
        //y位置为(根模块的高度-本模块高度)，就是本模块底部和父模块底部对齐的意思。
        y: root.height - height
        //设置背景图片，资源路径相对路径为 "images/pole.png"
        source: "images/pole.png"
    }

    Image {
        //设置ID为pinwheel，pinwheel为纸风车的意思
        id: pinwheel
        //设置本身的中心为父模块的中心
        anchors.centerIn: parent
        //设置背景图片，资源路径相对路径为 "images/pinwheel.png"
        source: "images/pinwheel.png"
        // visible: false
        Behavior on rotation {
            NumberAnimation { duration: 125 }
        }
    }

    Image {
        //设置ID为blur，blur为变模糊的意思
        id: blur
        //设置opacity为0，opacity为opacity的意思
        opacity: 0
        //设置本身的中心为父模块的中心
        anchors.centerIn: parent
        //设置背景图片，资源路径相对路径为 "images/blur.png"
        source: "images/blur.png"
        // visible: false
        //设置行为半径，Behavior是行为的意思，当关联的值改变时会自动触发下面的函数
        Behavior on rotation {
            //动作延迟125毫秒
            NumberAnimation { duration: 125 }
        }
        //设置行为不透明性，Behavior是行为的意思，当关联的值改变时会自动触发下面的函数
        Behavior on opacity {
            //动作延迟125毫秒
            NumberAnimation { duration: 125 }
        }

    }

    // M1>>
    //待定
    focus: true
    //鼠标事件区域
    //左键按下事件
    Keys.onLeftPressed: {
        //变模糊的不透明属性设置为1
        blur.opacity = 1
        //纸飞机的旋转属性值减小根模块的旋转幅度
        pinwheel.rotation -= root.rotationStep
        //变模糊的旋转属性值减小根模块的旋转幅度
        blur.rotation -= root.rotationStep
    }
    //右键按下事件
    Keys.onRightPressed: {
        //变模糊的不透明属性设置为0.5
        blur.opacity = 0.5
        //纸飞机的旋转属性值增加根模块的旋转幅度
        pinwheel.rotation += root.rotationStep
        //变模糊的旋转属性值增加根模块的旋转幅度
        blur.rotation += root.rotationStep
    }
    //键件松开事件
    Keys.onReleased: {
        //变模糊的不透明属性设置为0
        blur.opacity = 0
    }
    // <<M1
}
